import { Application, Session } from "mydog";
import { MysqlClient } from "../../../app/utils/mysql";
import { User } from "../../../app/entity/User";
import { ENUM_TABLE } from "../../../app/entity";

export default class Handler {

    app: Application;

    constructor(app: Application) {
        this.app = app;
    }

    async ping(msg: { "msg": string }, session: Session, next: Function) {
        next({ "msg": "pong" });

        console.log("rpc start")
        const data = await this.app.rpc("connector-server-1").connector.main.test(msg.msg);
        console.log("rpc end : ", data);


        let mysqlConfig = {
            "host": "127.0.0.1",
            "port": 3306,
            "user": "root",
            "password": "root1234",
            "database": "honor_db",
            "connectionLimit": 5
        }
        let db = new MysqlClient(mysqlConfig);
        let args: any[] = [];

        // console.info("inser table")
        // const user = new User();
        // user.name = "king"
        // delete (user as any).id;
        // const insertRes = await db.insert<User>(ENUM_TABLE.USER, user);
        // console.info("inser table: ", insertRes)
       
        let res = await db.select<User>(ENUM_TABLE.USER, "*", { "where": { "name": "reborn" }, "limit": 1 });
        console.info('select table: ', res)
    }
}